package com.freesky.provider.search.controller;

import com.freesky.common.dao.entity.SearchExpandLexcion;
import com.freesky.common.enums.ResponseEnum;
import com.freesky.common.exception.MyException;
import com.freesky.common.pojo.DataTablesResult;
import com.freesky.common.utils.reponse.JSONResponse;
import com.freesky.provider.search.service.IExpandLexiconService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Freesky
 */
@RestController
@RequestMapping("/search/expand-lexicon")
public class ExpandLexiconController {

    @Autowired
    private IExpandLexiconService expandLexiconService;

    @GetMapping(value = "/list")
    public DataTablesResult getList() {
        return expandLexiconService.getList();
    }

    @PostMapping(value = "/add")
    public JSONResponse add(@RequestBody SearchExpandLexcion searchExpandLexcion) {
        try {
            return expandLexiconService.add(searchExpandLexcion);
        } catch (Exception e) {
            throw new MyException(ResponseEnum.ADD_EXPAND_LEXICON_FAIL,e, null);
        }
    }

    @DeleteMapping(value = "/del/{ids}")
    public JSONResponse deleteById(@PathVariable(value = "ids") Integer[] ids) {
        try {
            return expandLexiconService.deleteById(ids);
        } catch (Exception e) {
            throw new MyException(ResponseEnum.DELETE_EXPAND_LEXICON_FAIL,e, null);
        }
    }
}
